/**
 * @author Fang Lu, fanglupku@gmail.com
 * 2011-5-13
 */
package com.autotag.wordnet;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import java.util.List;

import edu.mit.jwi.Dictionary;
import edu.mit.jwi.IDictionary;
import edu.mit.jwi.item.IIndexWord;
import edu.mit.jwi.item.ISynset;
import edu.mit.jwi.item.ISynsetID;
import edu.mit.jwi.item.IWord;
import edu.mit.jwi.item.IWordID;
import edu.mit.jwi.item.POS;
import edu.mit.jwi.item.Pointer;

public class WordNetDealer {
	public static void main(String argsp[]){
		String wnhome = System.getenv("WNHOME");
		System.out.println(wnhome);
		String path = wnhome + File.separator + "dict";
		try {
			URL url = new URL("file", null, path);
			IDictionary dict = new Dictionary(url);
			dict.open();
			
			IIndexWord idxWord = dict.getIndexWord("gene", POS.NOUN);
			IWordID wordID = idxWord.getWordIDs().get(0);
			IWord word = dict.getWord(wordID);
			ISynset synset = word.getSynset();
			List<ISynsetID> hypernyms =
				synset.getRelatedSynsets(Pointer.HYPERNYM);
			System.out.println("hyper size: " + hypernyms.size());
			
			List<IWord> words;
			for(ISynsetID sid : hypernyms){
				words = dict.getSynset(sid).getWords();
				System.out.print(sid + " {");
				for(Iterator<IWord> i = words.iterator(); i.hasNext();){
					System.out.print(i.next().getLemma());
					if(i.hasNext()) System.out.print(", ");
				}
				System.out.println("}");
			}
			
//			System.out.println("Id = " + wordID);
			System.out.println("Lemma = " + word.getLemma());
//			System.out.println("Gloss = " + word.getSynset().getGloss());
			
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
		}
	}
}
